import Vue from 'vue'
import VueRouter from 'vue-router'
// 异步组件加载
const Index = () => import('@/views/Index')
const Login = () => import('@/views/Login')
const Home = () => import('@/views/Home')
const Goods = () => import('@/views/Goods')
const Thanks = () => import('@/views/Thanks')
const GoodsDetail = () => import('@/views/GoodsDetail')
const User = () => import('@/views/User')
// 同步加载组件
// import Index from '@/views/Index'
// import Login from '@/views/Login'
// import Home from '@/views/Home'
// import Goods from '@/views/Goods'
// import Thanks from '@/views/Thanks'
// import GoodsDetail from '@/views/GoodsDetail'
// import User from '@/views/User'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home',
    name: 'home',
    component: Index,
    children: [
      {
        path: 'home',
        component: Home
      },
      {
        path: 'goods',
        component: Goods
      },
      {
        path: 'thanks',
        component: Thanks
      },
      {
        path: 'goodsDetail',
        name: 'goodsDetail',
        component: GoodsDetail
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/user',
    name: 'user',
    component: User,
    meta: {
      // 需要验证判断
      // 用来标记这个路由信息是否需要检测，true 表示要检测，false 表示不需要检测
      auth: true
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
